package com.jorado.redis;

import java.lang.reflect.Proxy;
import java.util.Map;

public class RedisUnSafeClient extends RedisClient {

    /**
     * redis处理类的构造函数
     *
     * @param redisClusters redis连接字符串
     */
    public RedisUnSafeClient(String redisClusters) {
        this(redisClusters, RedisClientInterface.DEFAULT_CONNECT_TIMEOUT, RedisClientInterface.DEFAULT_SOCKET_TIMEOUT,
                RedisClientInterface.DEFAULT_MAX_REDIRECTIONS);
    }

    /**
     * redis处理类的构造函数
     *
     * @param redisClusters   redis连接字符串
     * @param connectTimeout  连接超时时间
     * @param socketTimeout   读取超时的时间
     * @param maxRedirections 最大重试次数
     */
    public RedisUnSafeClient(String redisClusters, int connectTimeout, int socketTimeout, int maxRedirections) {
        this(redisClusters, connectTimeout, socketTimeout, maxRedirections, RedisClientInterface.DEFAULT_MAX_TOTAL,
                RedisClientInterface.DEFAULT_MAX_IDLE, RedisClientInterface.DEFAULT_MIN_IDLE, RedisClientInterface.DEFAULT_MAX_WAIT_MILLIS);
    }

    /**
     * redis处理类的构造函数
     *
     * @param redisClusters   redis连接字符串
     * @param connectTimeout  连接超时时间
     * @param socketTimeout   读取超时的时间
     * @param maxRedirections 最大重试次数
     * @param maxTotal        连接池配置参数(最大的连接数)
     * @param maxIdle         连接池配置参数(最大空闲连接)
     * @param minIdle         连接池配置参数(最少空闲连接)
     * @param maxWaitMillis   获取连接池中连接的最大等待时间
     */
    public RedisUnSafeClient(String redisClusters, int connectTimeout, int socketTimeout, int maxRedirections,
                             int maxTotal, int maxIdle, int minIdle, int maxWaitMillis) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final RedisClientInterface redisClient = (RedisClientInterface) Proxy.newProxyInstance(classLoader,
                new Class<?>[]{RedisClientInterface.class},
                new RedisClientProxy(new RedisClientImpl(redisClusters, connectTimeout, socketTimeout, maxRedirections,
                        maxTotal, maxIdle, minIdle, maxWaitMillis), true));
        setRedisClient(redisClient);
    }

    /**
     * 执行Redis的DEL命令
     *
     * @param key
     * @return
     */
    public Long del(String key) {
        return super.del(key);
    }

    /**
     * 执行Redis的EXISTS命令
     *
     * @param key
     * @return
     */
    public Boolean exists(String key) {
        return super.exists(key);
    }

    /**
     * 执行Redis的EXPIRE命令
     *
     * @param key
     * @param seconds
     * @return
     */
    public Long expire(final String key, final int seconds) {
        return super.expire(key, seconds);
    }

    /**
     * 执行Redis的EXPIREAT命令
     *
     * @param key
     * @param unixTime
     * @return
     */
    public Long expireAt(final String key, final long unixTime) {
        return super.expireAt(key, unixTime);
    }

    /**
     * 执行Redis的PERSIST命令
     *
     * @param key
     * @return
     */
    public Long persist(final String key) {
        return super.persist(key);
    }

    /**
     * 执行Redis的PEXPIRE命令
     *
     * @param key
     * @param milliseconds
     * @return
     */
    public Long pexpire(final String key, final long milliseconds) {
        return super.pexpire(key, milliseconds);
    }

    /**
     * 执行Redis的PEXPIREAT命令
     *
     * @param key
     * @param millisecondsTimestamp
     * @return
     */
    public Long pexpireAt(final String key, final long millisecondsTimestamp) {
        return super.pexpireAt(key, millisecondsTimestamp);
    }

    /**
     * 执行Redis的TTL命令
     *
     * @param key
     * @return
     */
    public Long ttl(final String key) {
        return super.ttl(key);
    }

    /**
     * 执行Redis的INCR命令
     *
     * @param key
     * @return
     */
    public Long incr(final String key) {
        return super.incr(key);
    }

    /**
     * 执行Redis的INCRBY命令
     *
     * @param key
     * @param integer
     * @return
     */
    public Long incrBy(final String key, final long integer) {
        return super.incrBy(key, integer);
    }

    /**
     * 执行Redis的SETNX命令
     *
     * @param key
     * @param value
     * @return
     */
    public Long setnx(final String key, final String value) {
        return super.setnx(key, value);
    }

    /**
     * 执行Redis的DECR命令
     *
     * @param key
     * @return
     */
    public Long decr(final String key) {
        return super.decr(key);
    }

    /**
     * 执行Redis的DECRBY命令
     *
     * @param key
     * @param integer
     * @return
     */
    public Long decrBy(final String key, final long integer) {
        return super.decrBy(key, integer);
    }

    /**
     * 执行Redis的HDEL命令
     *
     * @param key
     * @param field
     * @return
     */
    public Long hdel(final String key, final String... field) {
        return super.hdel(key, field);
    }

    /**
     * 执行Redis的HEXISTS命令
     *
     * @param key
     * @param field
     * @return
     */
    public Boolean hexists(final String key, final String field) {
        return super.hexists(key, field);
    }

    /**
     * 执行Redis的HINCRBY命令
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public Long hincrBy(final String key, final String field, final long value) {
        return super.hincrBy(key, field, value);
    }

    /**
     * 执行Redis的HLEN命令
     *
     * @param key
     * @return
     */
    public Long hlen(final String key) {
        return super.hlen(key);
    }

    /**
     * 执行Redis的HSET命令
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public Long hset(final String key, final String field, final String value) {
        return super.hset(key, field, value);
    }

    /**
     * 执行Redis的HSETNX命令
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public Long hsetnx(final String key, final String field, final String value) {
        return super.hsetnx(key, field, value);
    }

    /**
     * 执行Redis的LINSERT命令,where=before
     *
     * @param key
     * @param pivot
     * @param value
     * @return
     */
    public Long lbeforeinsert(final String key, final String pivot, final String value) {
        return super.lbeforeinsert(key, pivot, value);
    }

    /**
     * 执行Redis的LINSERT命令,where=after
     *
     * @param key
     * @param pivot
     * @param value
     * @return
     */
    public Long lafterinsert(final String key, final String pivot, final String value) {
        return super.lafterinsert(key, pivot, value);
    }

    /**
     * 执行Redis的LLEN命令
     *
     * @param key
     * @return
     */
    public Long llen(final String key) {
        return super.llen(key);
    }

    /**
     * 执行Redis的LPUSH命令
     *
     * @param key
     * @param string
     * @return
     */
    public Long lpush(final String key, final String... string) {
        return super.lpush(key, string);
    }

    /**
     * 执行Redis的LPUSHX命令
     *
     * @param key
     * @param string
     * @return
     */
    public Long lpushx(final String key, final String... string) {
        return super.lpushx(key, string);
    }

    /**
     * 执行Redis的LREM命令
     *
     * @param key
     * @param count
     * @param value
     * @return
     */
    public Long lrem(final String key, final long count, final String value) {
        return super.lrem(key, count, value);
    }

    /**
     * 执行Redis的RPUSH命令
     *
     * @param key
     * @param string
     * @return
     */
    public Long rpush(final String key, final String... string) {
        return super.rpush(key, string);
    }

    /**
     * 执行Redis的RPUSHX命令
     *
     * @param key
     * @param string
     * @return
     */
    public Long rpushx(final String key, final String... string) {
        return super.rpushx(key, string);
    }

    /**
     * 执行Redis的SADD命令
     *
     * @param key
     * @param member
     * @return
     */
    public Long sadd(final String key, final String... member) {
        return super.sadd(key, member);
    }

    /**
     * 执行Redis的SCARD命令
     *
     * @param key
     * @return
     */
    public Long scard(final String key) {
        return super.scard(key);
    }

    /**
     * 执行Redis的SISMEMBER命令
     *
     * @param key
     * @param member
     * @return
     */
    public Boolean sismember(final String key, final String member) {
        return super.sismember(key, member);
    }

    /**
     * 执行Redis的SREM命令
     *
     * @param key
     * @param member
     * @return
     */
    public Long srem(final String key, final String... member) {
        return super.srem(key, member);
    }

    /**
     * 执行Redis的ZADD命令
     *
     * @param key
     * @param scoreMembers
     * @return
     */
    public Long zadd(final String key, final Map<String, Double> scoreMembers) {
        return super.zadd(key, scoreMembers);
    }

    /**
     * 执行Redis的ZADD命令
     *
     * @param key
     * @param member
     * @return
     */
    public Long zadd(final String key, final double score, final String member) {
        return super.zadd(key, score, member);
    }

    /**
     * 执行Redis的ZCARD命令
     *
     * @param key
     * @return
     */
    public Long zcard(final String key) {
        return super.zcard(key);
    }

    /**
     * 执行Redis的ZCOUNT命令
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Long zcount(final String key, final String min, final String max) {
        return super.zcount(key, min, max);
    }

    /**
     * 执行Redis的ZCOUNT命令
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Long zcount(final String key, final double min, final double max) {
        return super.zcount(key, min, max);
    }

    /**
     * 执行Redis的ZINCRBY命令
     *
     * @param key
     * @param score
     * @param member
     * @return
     */
    public Double zincrby(final String key, final double score, final String member) {
        return super.zincrby(key, score, member);
    }

    /**
     * 执行Redis的ZRANK命令, 如果出错，返回-1
     *
     * @param key
     * @param member
     * @return
     */
    public Long zrank(final String key, final String member) {
        return super.zrank(key, member);
    }

    /**
     * 执行Redis的ZREM命令
     *
     * @param key
     * @param member
     * @return
     */
    public Long zrem(final String key, final String... member) {
        return super.zrem(key, member);
    }

    /**
     * 执行Redis的ZREMRANGEBYRANK命令
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Long zremrangeByRank(final String key, final long start, final long end) {
        return super.zremrangeByRank(key, start, end);
    }

    /**
     * 执行Redis的ZREMRANGEBYSCORE命令
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Long zremrangeByScore(final String key, final double start, final double end) {
        return super.zremrangeByScore(key, start, end);
    }

    /**
     * 执行Redis的ZREVRANK命令
     *
     * @param key
     * @param member
     * @return
     */
    public Long zrevrank(final String key, final String member) {
        return super.zrevrank(key, member);
    }

    /**
     * 执行Redis的ZSCORE命令
     *
     * @param key
     * @param member
     * @return
     */
    public Double zscore(final String key, final String member) {
        return super.zscore(key, member);
    }

}
